package com.lovelyj.trip_by_train.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lovelyj.trip_by_train.common.R;
import com.lovelyj.trip_by_train.entity.Arrive;
import com.lovelyj.trip_by_train.entity.DailySeat;
import com.lovelyj.trip_by_train.entity.Train;
import com.lovelyj.trip_by_train.service.DailySeatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.time.LocalDate;
import java.util.List;

@Slf4j
@RequestMapping("/dailySeat")
@RestController
public class DailySeatController {

    @Autowired
    private DailySeatService dailySeatService;

    @GetMapping("/select")
    public R<Page<DailySeat>> select(HttpServletRequest request,Integer page ,String trainNum, String travelDate) {
        log.info(trainNum+" "+travelDate);
        Page<DailySeat> pageInfo=new Page<>(page,10);
        LambdaQueryWrapper<DailySeat> queryWrapper = new LambdaQueryWrapper<DailySeat>();
        queryWrapper.eq(DailySeat::getTrainNum, trainNum);
        queryWrapper.eq(DailySeat::getTravelDate,LocalDate.parse(travelDate));
        queryWrapper.orderByAsc(DailySeat::getCoachNum);
        queryWrapper.orderByAsc(DailySeat::getSeatRow);
        queryWrapper.orderByAsc(DailySeat::getSeatCol);
        dailySeatService.page(pageInfo,queryWrapper);
        return R.success(pageInfo);
    }


}
